
###############################
### Heckman and ANES models ###
###############################

library(ggplot2)
library(lmtest)
library(sandwich)
library(MASS)
library(plyr)
library(stargazer)
library(dplyr)
library(data.table)
library(lfe)
library(interflex)
library(sampleSelection)
library(survey)
library(xtable)

# Set working directory to current folder

### SCF and ANES data
load("anes_data.RData")
load("scf_data.RData")

anes_data[ , owner_num := as.numeric(owner_fac) ]
anes_data[ , party_id1_num := as.numeric(party_id1) ]
anes_data[ , marital_num := as.numeric(marital_fac) ]

# Prep data for support for social insurance; remove NA
anes_data_v1 <- anes_data
anes_data_v1[ , fed_spend_aid_poor := NULL ]
anes_data_v1 <- na.omit(anes_data) 


### Heckman selection model
heckvan1 <- selection(has_debt ~ age + income_num + highest_degree + owner + has_children + marital_fac + race2 + gender_num,
                      ihs_unscrd_debt_v1 ~ age + income_num + highest_degree + owner + has_children + marital_fac + race2 + gender_num,
                      data=scf_data, weights=scf_data$wgt, method="2step")

summary(heckvan1)


### Predicted probability has debt 
prob.has.debt <- predict(heckvan1, part = "selection", type="response", anes_data_v1)
summary(prob.has.debt)

#### Predicted amount of unsecured debt
pred.amt.unscrd.debt <- predict(heckvan1, part = "outcome",  type="conditional", anes_data_v1)[,2]
summary(pred.amt.unscrd.debt)

anes_data_v1[ , prob_has_debt := prob.has.debt ]
anes_data_v1[ , has_debt := ifelse(prob_has_debt > 0.5, 1, 0) ]

# If probability of having debt > 0.5, then give predicted amount, otherwise zero 
anes_data_v1[ , pred_ihs_unscrd_debt := ifelse(prob.has.debt > 0.5, pred.amt.unscrd.debt, 0) ]


### Predict monthly consumer debt payments
heckvan2 <- selection(has_debt ~ age + income_num + highest_degree + owner + has_children + marital_fac + race2 + gender_num,
                      ihs_tpay_cons_dbt_v1 ~ age + income_num + highest_degree + owner + has_children + marital_fac + race2 + gender_num,
                      data=scf_data, weights=scf_data$wgt, method="2step")

#### Predicted amount of monthly consumer debt repayment
pred.amt.tpay.cons.dbt <- predict(heckvan2, part = "outcome",  type="conditional", anes_data_v1)[,2]

# If probability of having debt > 0.5, then give predicted amount, otherwise zero 
anes_data_v1[ , pred_ihs_tpay_cons_dbt := ifelse(prob.has.debt > 0.5, pred.amt.tpay.cons.dbt, 0) ]



###############
### Table 2 ###
###############

heck.prob1 <- heckvan1$probit
names(heck.prob1$estimate) <- gsub("XS","",names(heck.prob1$estimate))

heck.lm_unscrd_dbt <- heckvan1$lm
names(heck.lm_unscrd_dbt$coefficients) <- gsub("XO","",names(heck.lm_unscrd_dbt$coefficients))

heck.lm_tpay_cons_dbt <- heckvan2$lm
names(heck.lm_tpay_cons_dbt$coefficients) <- gsub("XO","",names(heck.lm_tpay_cons_dbt$coefficients))

stargazer(heck.prob1, heck.lm_unscrd_dbt, heck.lm_tpay_cons_dbt,
          omit.stat = c("ser"), omit= "factor", 
          no.space=T, digits.extra=0, digits=2, align=T, type="text")

vars_heckit <- c("Age","Household income","High school","Less than high school","Some college","Homeowner","Has children","Single",
                 "Black","Hispanic","White","Male")

stargazer(heck.prob1, heck.lm_unscrd_dbt, heck.lm_tpay_cons_dbt,
          omit.stat = c("ser","F","chi2"), omit= "factor", 
          covariate.labels = vars_heckit,  dep.var.labels = c("Has debt","Unsecured debt (log)"),
          no.space=T, digits.extra=0, digits=2, align=T, type="text")


#################
### Table A.5 ###
#################

stargazer(scf_data[ ,.(ihs_unscrd_debt_v1,ihs_tpay_cons_dbt_v1,age,income_num) ], 
          summary.stat = c("n","min","max","mean","median"), no.space=T, digits.extra=0, digits=2, align=T, type="text",
          covariate.labels = c("Unsecured debt (log)","Monthly unsecured debt repayment (log)","Age","Household income (groups)"))

stargazer(scf_data[ has_debt == 1 ,.(ihs_unscrd_debt_v1,ihs_tpay_cons_dbt_v1) ], 
          summary.stat = c("n","min","max","mean","median"), no.space=T, digits.extra=0, digits=2, align=T, type="text",
          covariate.labels = c("Unsecured debt (log)","Monthly unsecured debt repayment (log)","Age","Household income (groups)"))

stargazer(anes_data_v1[ ,.(pred_ihs_unscrd_debt,pred_ihs_tpay_cons_dbt,age,income_num) ], 
          summary.stat = c("n","min","max","mean","median"), no.space=T, digits.extra=0, digits=2, align=T, type="text",
          covariate.labels = c("Unsecured debt (log)*","Monthly unsecured debt repayment (log)*","Age","Household income (groups)"))

stargazer(anes_data_v1[ has_debt == 1  ,.(pred_ihs_unscrd_debt,pred_ihs_tpay_cons_dbt) ], 
          summary.stat = c("n","min","max","mean","median"), no.space=T, digits.extra=0, digits=2, align=T, type="text",
          covariate.labels = c("Unsecured debt (log)*","Monthly unsecured debt repayment (log)*"))



#################
### Table A.6 ###
#################

svy_scf_v1 <- svydesign(id=~y1, weights=~wgt, data=scf_data)

tab.scf_v1.debt <- data.table(prop.table(svytable( ~ has_debt, svy_scf_v1)))
tab.scf_v1.race <- data.table(prop.table(svytable( ~ race2, svy_scf_v1)))
tab.scf_v1.educ <- data.table(prop.table(svytable( ~ highest_degree, svy_scf_v1)))
tab.scf_v1.marital <- data.table(prop.table(svytable( ~ marital_fac, svy_scf_v1)))
tab.scf_v1.gender <- data.table(prop.table(svytable( ~ gender_num, svy_scf_v1)))
tab.scf_v1.children <- data.table(prop.table(svytable( ~ has_children, svy_scf_v1)))
tab.scf_v1.owner <- data.table(prop.table(svytable( ~ owner, svy_scf_v1)))

names(tab.scf_v1.debt)[1] <- "type"
names(tab.scf_v1.race)[1] <- "type"
names(tab.scf_v1.educ)[1] <- "type"
names(tab.scf_v1.marital)[1] <- "type"
names(tab.scf_v1.gender)[1] <- "type"
names(tab.scf_v1.children)[1] <- "type"
names(tab.scf_v1.owner)[1] <- "type"

tab.scf_v1.gender[ , type := paste("gen",type,sep=""), type ]
tab.scf_v1.children[ , type := paste("child",type,sep=""), type]
tab.scf_v1.race[ , type := paste("race",type,sep=""), type]
tab.scf_v1.educ[ , type := paste("educ",type,sep=""), type]
tab.scf_v1.marital[ , type := paste("marital",type,sep=""), type]
tab.scf_v1.owner[ , type := paste("own",type,sep=""), type]
tab.scf_v1.debt[ , type := paste("debt",type,sep=""), type]

tab_scf_v1 <- as.data.table(rbind(tab.scf_v1.race,tab.scf_v1.educ,tab.scf_v1.marital,
                                  tab.scf_v1.gender,tab.scf_v1.children,tab.scf_v1.owner,tab.scf_v1.debt))
names(tab_scf_v1)[2] <- "SCF"

# ANES
svy_anes_v1 <- svydesign(id=~id_comb, weights=~1, data=anes_data_v1)

tab.anes_v1.race <- data.table(prop.table(svytable( ~ race2, svy_anes_v1)))
tab.anes_v1.educ <- data.table(prop.table(svytable( ~ highest_degree, svy_anes_v1)))
tab.anes_v1.marital <- data.table(prop.table(svytable( ~ marital_fac, svy_anes_v1)))
tab.anes_v1.gender <- data.table(prop.table(svytable( ~ gender_num, svy_anes_v1)))
tab.anes_v1.children <- data.table(prop.table(svytable( ~ has_children, svy_anes_v1)))
tab.anes_v1.owner <- data.table(prop.table(svytable( ~ owner, svy_anes_v1)))
tab.anes_v1.debt <- data.table(prop.table(svytable( ~ has_debt, svy_anes_v1)))

names(tab.anes_v1.race)[1] <- "type"
names(tab.anes_v1.educ)[1] <- "type"
names(tab.anes_v1.marital)[1] <- "type"
names(tab.anes_v1.gender)[1] <- "type"
names(tab.anes_v1.children)[1] <- "type"
names(tab.anes_v1.owner)[1] <- "type"
names(tab.anes_v1.debt)[1] <- "type"

tab.anes_v1.gender[ , type := paste("gen",type,sep=""), type ]
tab.anes_v1.children[ , type := paste("child",type,sep=""), type]
tab.anes_v1.race[ , type := paste("race",type,sep=""), type]
tab.anes_v1.educ[ , type := paste("educ",type,sep=""), type]
tab.anes_v1.marital[ , type := paste("marital",type,sep=""), type]
tab.anes_v1.owner[ , type := paste("own",type,sep=""), type]
tab.anes_v1.debt[ , type := paste("debt",type,sep=""), type]

tab_anes_v1 <- as.data.table(rbind(tab.anes_v1.race,tab.anes_v1.educ,tab.anes_v1.marital,
                                   tab.anes_v1.gender,tab.anes_v1.children,tab.anes_v1.owner,tab.anes_v1.debt))
names(tab_anes_v1)[2] <- "ANES"

tab_comb_v1 <- merge(tab_scf_v1, tab_anes_v1, by="type",all=T)

rownames(tab_comb_v1) <- c("No children","children","Has no debt","Has debt","High school","College","Less than high school","Some college",
                           "Female","Male","Married","Single","Owner n","Owner y","Black","Hispanic","White","Other")

tab_comb_v1[ , type := NULL]

(tab_comb_v1_x <- xtable(tab_comb_v1, include.colnames=T, caption="Summary statistics"))



#################
### Table A.9 ###
#################

svy_anes_wgt <- svydesign(id=~id_comb, weights=~WT04, data=anes_data_v1)

op_sex <- prop.table(svytable( ~ gender_num + fed_spend_welfare_num, svy_anes_wgt), margin=1)*100
op_unemp <- prop.table(svytable( ~ unemployed + fed_spend_welfare_num, svy_anes_wgt), margin=1)*100
op_race <- prop.table(svytable( ~ race + fed_spend_welfare_num, svy_anes_wgt), margin=1)*100
op_educ <- prop.table(svytable( ~ highest_degree + fed_spend_welfare_num, svy_anes_wgt), margin=1)*100
op_party <- prop.table(svytable( ~ party_id1 + fed_spend_welfare_num, svy_anes_wgt), margin=1)*100
op_inc <- prop.table(svytable( ~ income_num + fed_spend_welfare_num, svy_anes_wgt), margin=1)*100
op_empl_stat <- prop.table(svytable( ~ empl_stat + fed_spend_welfare_num, svy_anes_wgt), margin=1)*100

(anes_perc_tab <- rbind(op_sex,op_empl_stat,op_race,op_educ,op_party,op_inc))

rownames(anes_perc_tab) <- c("Male","Female","Disabled","Homemaker","Retired","Student","Temporary laid off","Unemployed",
                             "Working full-time","Working part-time","Asian","Black","Hispanic","Native","White",
                             "Less than high school","College","High school","Some college","Independent","Democrat","Republican",
                             "< $14,999","$15,000 - $34,999","$35,000 - $49,999","$50,000 - $64,999","$65,000 - $84,999",
                             "More than $84,999")

colnames(anes_perc_tab) <- c("Decrease","Same","Increase")

(tab <- xtable(anes_perc_tab, include.colnames=T, caption="Opinion"))



########################################
### Table 3 Panel A (and Table A.10) ###
########################################

### Models for imputed debt level on preferences
anes_mod_debt_imput_v1.1 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr 
                                 | id_comb + year | 0 | id_comb, anes_data_v1)

anes_mod_debt_imput_v1.2 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year
                                 | id_comb + year | 0 | id_comb, anes_data_v1)

anes_mod_debt_imput_v1.3 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac
                                 | id_comb + year | 0 | id_comb, anes_data_v1)

anes_mod_debt_imput_v1.4 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac + 
                                   log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc +
                                   govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density 
                                 | id_comb + year | 0 | id_comb, anes_data_v1[ ])

# Table 3 Panel A
stargazer(anes_mod_debt_imput_v1.1, anes_mod_debt_imput_v1.2, anes_mod_debt_imput_v1.3, anes_mod_debt_imput_v1.4,
          omit.stat = c("ser","F"), omit= "factor", 
          covariate.labels = c("Unsecured household debt (log)","UI replacement rate","Unsecured household debt (log) $\\times$ UI replacement rate"),
          dep.var.labels = "Support for welfare spending", 
          add.lines = list(c("Mean DV",
                             round(mean(anes_mod_debt_imput_v1.1$fitted.values),2), round(mean(anes_mod_debt_imput_v1.2$fitted.values),2),
                             round(mean(anes_mod_debt_imput_v1.3$fitted.values),2), round(mean(anes_mod_debt_imput_v1.4$fitted.values),2)),
                           c("Individual FE","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$"),
                           c("Year FE","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$"),
                           c("Individual-level covariates","-","$\\checkmark$","$\\checkmark$"),
                           c("Predictor covariates","-","-","$\\checkmark$","$\\checkmark$"),
                           c("State-level covariates","-","-","-","$\\checkmark$")),
          no.space=T, digits.extra=0, digits=2, align=T, type="text",
          keep = c("pred_ihs_unscrd_debt","replacement_ratio1_yr"), title = "Effect of UI Replacement Rates and Unsecured Debt on Support for Welfare Spending")


### Full results for Table A.10
labels_anes_mod_debt_imput_v1 <- c("Unsecured household debt (log)","UI replacement rate",
                                   "Unemployed","Retired","Democrat","Republican","Financial situation: got worse","Financial situation: got better",
                                   "Household income","Homeowner","Married",
                                   "GSP (per-capita, log)","Change GSP","Unemployment rate","Expenditures (per-capita, log)",
                                   "Revenues (per-capita, log)","Revenues from Fed. Govt. Transfers","Avg. disposable income (log)",
                                   "Democrat as governor", "Share Democrats in house","Median duration of unemployment",
                                   "State policy liberalism","Union density",
                                   "Unsecured household debt (log) $\\times$ UI replacement rate")

stargazer(anes_mod_debt_imput_v1.1, anes_mod_debt_imput_v1.2, anes_mod_debt_imput_v1.3, anes_mod_debt_imput_v1.4,
          omit.stat = c("ser","F"), omit= "factor", 
          covariate.labels = labels_anes_mod_debt_imput_v1, dep.var.labels = "Support for welfare spending",
          add.lines = list(c("Mean DV",
                             round(mean(anes_mod_debt_imput_v1.1$fitted.values),2), round(mean(anes_mod_debt_imput_v1.2$fitted.values),2),
                             round(mean(anes_mod_debt_imput_v1.3$fitted.values),2), round(mean(anes_mod_debt_imput_v1.4$fitted.values),2)),
                           c("Individual FE","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$"),
                           c("Year FE","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$")),
          no.space=T, digits.extra=0, digits=2, align=T, type="latex", title = "Effect of UI Replacement Rates and Unsecured Debt on Support for Welfare Spending")


#################
### Figure 4a ###
#################

anes_mod_debt_imput_v1_bin_v1 <- interflex(Y = "fed_spend_welfare_num", D = "pred_ihs_unscrd_debt", X = "replacement_ratio1_yr", 
                                            Z = c("unemployed","retired","party_id1_num","fin_sit_last_year","income_num","owner_num","marital_num",
                                                  "log_real1gsppc", "gsptotal_PC_pct_chg", "unemploy_a", "log_real1exppc", "log_real1revpc","afgrant_log","log_disinc",
                                                    "govparty_a", "hs_dem_prop_all", "median_duration_in_weeks", "pollib_median", "union_density" ), 
                                            FE = c("id_comb","year"), estimator = "binning", vartype = "robust", cl="id_comb", 
                                            data = anes_data_v1, na.rm=T)

(plot_anes_mod_debt_imput_v1_bin_v1 <- plot(anes_mod_debt_imput_v1_bin_v1, 
                                            Ylabel = "Support for Welfare Spending", Dlabel = "Unsecured debt (log)\n", Xlabel = "UI Replacement Rate",
                                            ylab = c("Marginal effect of predicted unsecured\ndebt (log) on support for welfare spending"),
                                            xlab = c("Average UI replacement rate"), Xdistr = "density", bin.labs = T,
                                            cex.lab = 0.7, cex.axis = 0.6, xlim=c(0.37,0.55)))



########################################
### Table 3 Panel B (and Table A.11) ###
########################################

### Model with debt-to-income ratio
anes_mod_debt_ratio_v1.1 <- felm(fed_spend_welfare_num ~ debt_inc_ratio_low_yr*replacement_ratio1_yr 
                                 | id_comb | 0 | id_comb, anes_data_v1)

anes_mod_debt_ratio_v1.2 <- felm(fed_spend_welfare_num ~ debt_inc_ratio_low_yr*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year 
                                 | id_comb | 0 | id_comb, anes_data_v1)

anes_mod_debt_ratio_v1.3 <- felm(fed_spend_welfare_num ~ debt_inc_ratio_low_yr*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac
                                 | id_comb | 0 | id_comb, anes_data_v1)

anes_mod_debt_ratio_v1.4 <- felm(fed_spend_welfare_num ~ debt_inc_ratio_low_yr*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac + 
                                   log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc 
                                 | id_comb | 0 | id_comb, anes_data_v1)

anes_mod_debt_ratio_v1.5 <- felm(fed_spend_welfare_num ~ debt_inc_ratio_low_yr*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac + 
                                   log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc + 
                                   govparty_a + hs_dem_prop_all + median_duration_in_weeks | id_comb | 0 | id_comb, anes_data_v1)

# Table 3 Panel B
stargazer(anes_mod_debt_ratio_v1.1, anes_mod_debt_ratio_v1.2, anes_mod_debt_ratio_v1.3, anes_mod_debt_ratio_v1.5,
          omit.stat = c("ser","F"), omit= "factor", 
          covariate.labels = c("Debt-to-income ratio","UI replacement rate","Debt-to-income ratio $\\times$ UI replacement rate"),
          dep.var.labels = "Support for welfare spending",
          add.lines = list(c("Mean DV",
                             round(mean(anes_mod_debt_ratio_v1.1$fitted.values),2), round(mean(anes_mod_debt_ratio_v1.2$fitted.values),2),
                             round(mean(anes_mod_debt_ratio_v1.3$fitted.values),2), round(mean(anes_mod_debt_ratio_v1.5$fitted.values),2)),
                           c("Individual FE","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$"),
                           c("Individual-level covariates","-","$\\checkmark$","$\\checkmark$"),
                           c("Predictor covariates","-","-","$\\checkmark$","$\\checkmark$"),
                           c("State-level covariates","-","-","-","$\\checkmark$")),
          no.space=T, digits.extra=0, digits=2, align=T, type="text",
          keep = c("debt_inc_ratio_low_yr","replacement_ratio1_yr"), 
          title = "Effect of UI Replacement Rates and Debt/Income Ratios on Support for Welfare Spending")


### Table A.11
labels_anes_mod_debt_ratio_v1 <- c("Debt-to-income ratio","UI replacement rate",
                                   "Unemployed","Retired","Democrat","Republican","Financial situation: got worse","Financial situation: got better",
                                   "Household income","Homeowner","Married","GSP (per-capita, log)","Change GSP","Unemployment rate","Expenditures (per-capita, log)",
                                   "Revenues (per-capita, log)","Revenues from Fed. Govt. Transfers","Disposable income (avg, log)",
                                   "Democrat as governor", "Share Democrats in house","Median duration of unemployment",
                                   "Debt-to-income ratio $\\times$ UI replacement rate")

stargazer(anes_mod_debt_ratio_v1.1, anes_mod_debt_ratio_v1.2, anes_mod_debt_ratio_v1.3, anes_mod_debt_ratio_v1.5,
          omit.stat = c("ser","F"), omit= "factor", 
          covariate.labels = labels_anes_mod_debt_ratio_v1, dep.var.labels = "Support for welfare spending",
          add.lines = list(c("Mean DV",
                             round(mean(anes_mod_debt_ratio_v1.1$fitted.values),2), round(mean(anes_mod_debt_ratio_v1.2$fitted.values),2),
                             round(mean(anes_mod_debt_ratio_v1.3$fitted.values),2), round(mean(anes_mod_debt_ratio_v1.5$fitted.values),2)),
                           c("Individual FE","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$"),
                           c("Year FE","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$")),
          no.space=T, digits.extra=0, digits=2, align=T, type="text", 
          title = "Effect of UI Replacement Rates and Debt/Income Ratios on Support for Welfare Spending")


#################
### Figure 4b ###
#################

(anes_mod_debt_ratio_bin_v1 <- interflex(Y = "fed_spend_welfare_num", D = "debt_inc_ratio_low_yr", X = "replacement_ratio1_yr", 
                                         Z = c("unemployed","retired","party_id1_num","fin_sit_last_year","income_num","owner_num","marital_num"), 
                                         FE = c("id_comb"), estimator = "binning", vartype = "robust", cl="id_comb", 
                                         data = anes_data_v1, na.rm=T))

(plot_anes_mod_debt_ratio_bin_v1 <- plot(anes_mod_debt_ratio_bin_v1, 
                                         Ylabel = "Support for Welfare Spending", Dlabel = "Unsecured debt (log)\n", Xlabel = "UI Replacement Rate",
                                         ylab = c("Marginal effect of debt/income ratio\non support for welfare spending"),
                                         xlab = c("Average UI replacement rate"), Xdistr = "density", bin.labs = T,
                                         xlim=c(0.37,0.55), cex.lab = 0.7, cex.axis = 0.6))


##################
### Table A.12 ###
##################

### Model with monthly debt repayment
anes_mod_debt_repay_imput_v1.1 <- felm(fed_spend_welfare_num ~ pred_ihs_tpay_cons_dbt*replacement_ratio1_yr 
                                 | id_comb + year | 0 | id_comb, anes_data_v1)

anes_mod_debt_repay_imput_v1.2 <- felm(fed_spend_welfare_num ~ pred_ihs_tpay_cons_dbt*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year
                                 | id_comb + year | 0 | id_comb, anes_data_v1)

anes_mod_debt_repay_imput_v1.3 <- felm(fed_spend_welfare_num ~ pred_ihs_tpay_cons_dbt*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac
                                 | id_comb + year | 0 | id_comb, anes_data_v1)

anes_mod_debt_repay_imput_v1.5 <- felm(fed_spend_welfare_num ~ pred_ihs_tpay_cons_dbt*replacement_ratio1_yr + 
                                         unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac + 
                                         log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc +
                                         govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density 
                                 | id_comb + year | 0 | id_comb, anes_data_v1)


labels_anes_mod_debt_repay_imput_v1 <- c("Monthly unsecured debt repayment (log)","UI replacement rate",
                                         "Unemployed","Retired","Democrat","Republican","Financial situation: got worse","Financial situation: got better",
                                         "Household income","Homeowner","Married",
                                         "GSP (per-capita, log)","Change GSP","Unemployment rate","Expenditures (per-capita, log)",
                                         "Revenues (per-capita, log)","Revenues from Fed. Govt. Transfers","Avg. disposable income (log)",
                                         "Democrat as governor", "Share Democrats in house","Median duration of unemployment",
                                         "State policy liberalism","Union density",
                                         "Monthly unsecured debt repayment (log) $\\times$ UI replacement rate")

stargazer(anes_mod_debt_repay_imput_v1.1, anes_mod_debt_repay_imput_v1.2, anes_mod_debt_repay_imput_v1.3, anes_mod_debt_repay_imput_v1.5,
          omit.stat = c("ser","F"), omit= "factor", 
          covariate.labels = labels_anes_mod_debt_repay_imput_v1, dep.var.labels = "Support for welfare spending",
          add.lines = list(c("Mean DV",
                             round(mean(anes_mod_debt_repay_imput_v1.1$fitted.values),2), round(mean(anes_mod_debt_repay_imput_v1.2$fitted.values),2),
                             round(mean(anes_mod_debt_repay_imput_v1.3$fitted.values),2), round(mean(anes_mod_debt_repay_imput_v1.5$fitted.values),2)),
                           c("Individual FE","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$"),
                           c("Year FE","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$")),
          no.space=T, digits.extra=0, digits=2, align=T, type="text", title = "Effect of UI Replacement Rates and Debt Repayment on Support for Welfare Spending")



#########################
### Tables 4 and A.14 ###
#########################

### Lagged unemployment rate 
anes_data_v1[ unemploy_a_lag < mean(unemploy_a_lag, na.rm=T) , unemploy_a_lag_grp := "low" ]
anes_data_v1[ unemploy_a_lag >= mean(unemploy_a_lag, na.rm=T) , unemploy_a_lag_grp := "high" ]

anes_data_v1[ , unemploy_a_lag_grp := factor(unemploy_a_lag_grp) ]
anes_data_v1[ , unemploy_a_lag_grp := relevel(unemploy_a_lag_grp, "low")]

anes_mod_5.1 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                       unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac
                     | abbr + year | 0 | abbr, anes_data_v1[ unemploy_a_lag_grp == "low"  ])

summary(anes_mod_5.1)

anes_mod_5.2 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                       unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac + 
                       log_real1gsppc + gsptotal_PC_pct_chg + log_real1exppc + log_real1revpc + afgrant_log + log_disinc  + 
                       govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density 
                     | abbr + year | 0 | abbr, anes_data_v1[ unemploy_a_lag_grp == "low"  ])

summary(anes_mod_5.2)

anes_mod_5.3 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr +
                       unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac
                     | abbr + year | 0 | abbr, anes_data_v1[ unemploy_a_lag_grp == "high" ])

summary(anes_mod_5.3)

anes_mod_5.4 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr +
                       unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac + 
                       log_real1gsppc + gsptotal_PC_pct_chg + log_real1exppc + log_real1revpc + afgrant_log + log_disinc +  
                       govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density 
                     | abbr + year | 0 | abbr, anes_data_v1[ unemploy_a_lag_grp == "high" ])

summary(anes_mod_5.4)


### By financial situation
anes_mod_pred_v1_8.1 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                               unemployed + retired + party_id1 + income_num + owner_fac + marital_fac + 
                               log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc + 
                               govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density 
                             | id_comb + year | 0 | id_comb, anes_data_v1[ fin_sit_last_year == "better" ]) # things were better last year, i.e. things got worse today

anes_mod_pred_v1_8.2 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                               unemployed + retired + party_id1 + income_num + owner_fac + marital_fac + 
                               log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc + 
                               govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density 
                             | id_comb + year | 0 | id_comb, anes_data_v1[ fin_sit_last_year == "same" ])

anes_mod_pred_v1_8.3 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                               unemployed + retired + party_id1 + income_num + owner_fac + marital_fac + 
                               log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc + 
                               govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density 
                             | id_comb + year | 0 | id_comb, anes_data_v1[ fin_sit_last_year == "worse" ])


### By PID
anes_mod_2.3 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                       unemployed + retired + fin_sit_last_year + income_num + owner_fac + marital_fac | id_comb + year | 0 | id_comb, 
                     anes_data_v1[ party_id1 == "dem" ])

anes_mod_2.4 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                       unemployed + retired + fin_sit_last_year + income_num + owner_fac + marital_fac + 
                       log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc + 
                       govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density 
                       | id_comb + year | 0 | id_comb, anes_data_v1[ party_id1 == "dem" ])

anes_mod_2.5 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                       unemployed + retired + fin_sit_last_year + income_num + owner_fac + marital_fac | id_comb + year | 0 | id_comb, 
                     anes_data_v1[ party_id1 == "rep" ])

anes_mod_2.6 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                       unemployed + retired + fin_sit_last_year + income_num + owner_fac + marital_fac + 
                       log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc + 
                       govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density 
                     | id_comb + year | 0 | id_comb, anes_data_v1[ party_id1 == "rep" ])

### Table 4
vars_anes_mod_pred_vX_comb <- c("Unsecured household debt (log)","UI replacement rate","Unemployed","Retired","Democrat","Republican",
                                "Financial situation: got worse","Financial situation: got better","Household income","Homeowner","Married",
                                "GSP (per-capita, log)","Change GSP","Unemployment rate","Expenditures (per-capita, log)",
                                "Revenues (per-capita, log)","Revenues from Fed. Govt. Transfers","Avg. disposable income (log)",
                                "Democrat as governor", "Share Democrats in house","Median duration of unemployment","State policy liberalism","Union density",
                                "Unsecured household debt (log) $\\times$ UI replacement rate")

stargazer(anes_mod_5.2, anes_mod_5.4, anes_mod_pred_v1_8.1, anes_mod_pred_v1_8.2, anes_mod_pred_v1_8.3, anes_mod_2.4, anes_mod_2.6,
          column.labels = c("Unemployment: low","Unemployment: high","Fin sit: got worse","Fin sit: same","Fin sit: got better","PID dem","PID rep"), 
          omit.stat = c("ser","F"), omit= "factor", table.placement = "ht!",
          covariate.labels = c("Unsecured household debt (log)","UI replacement rate","Unsecured household debt (log) $\\times$ UI replacement rate"),
          dep.var.labels = "Support for welfare spending", 
          add.lines = list(c("Mean DV",
                             round(mean(anes_mod_5.2$fitted.values),2),round(mean(anes_mod_5.4$fitted.values),2),
                             round(mean(anes_mod_pred_v1_8.1$fitted.values),2),round(mean(anes_mod_pred_v1_8.2$fitted.values),2),
                             round(mean(anes_mod_pred_v1_8.3$fitted.values),2),round(mean(anes_mod_2.4$fitted.values),2),round(mean(anes_mod_2.6$fitted.values),2)),
                           c("Individual FE","-","-","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$"),
                           c("Year FE","$\\checkmark$","$\\checkmark$","-","-","-","-","-"),
                           c("Individual-level controls","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$"),
                           c("State-level controls","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$")),
          no.space=T, digits.extra=0, digits=2, align=T, type="text",
          keep = c("pred_ihs_unscrd_debt","replacement_ratio1_yr"))



# Table A.14
stargazer(anes_mod_5.2, anes_mod_5.4, anes_mod_pred_v1_8.1, anes_mod_pred_v1_8.2, anes_mod_pred_v1_8.3, anes_mod_2.4, anes_mod_2.6,
          column.labels = c("Unemployment: low","Unemployment: high","Fin sit: got worse","Fin sit: same","Fin sit: got better","PID dem","PID rep"), 
          omit.stat = c("ser","F"), omit= "factor", table.placement = "ht!",
          covariate.labels = vars_anes_mod_pred_vX_comb, dep.var.labels = "Support for welfare spending",
          add.lines = list(c("Mean DV",
                             round(mean(anes_mod_5.2$fitted.values),2),round(mean(anes_mod_5.4$fitted.values),2),
                             round(mean(anes_mod_pred_v1_8.1$fitted.values),2),round(mean(anes_mod_pred_v1_8.2$fitted.values),2),
                             round(mean(anes_mod_pred_v1_8.3$fitted.values),2),round(mean(anes_mod_2.4$fitted.values),2),round(mean(anes_mod_2.6$fitted.values),2)),
                           c("Individual FE","-","-","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$"),
                           c("Year FE","$\\checkmark$","$\\checkmark$","-","-","-","-","-")),
          no.space=T, digits.extra=0, digits=2, align=T, type="text")



##################
### Table A.15 ###
##################

anes_data_v1[ , fin_sit_last_year := as.factor(fin_sit_last_year) ]
anes_data_v1[ , fin_sit_last_year := relevel(fin_sit_last_year, "worse") ]

anes_mod_pred_v1_8_TX <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr*fin_sit_last_year + 
                               unemployed + retired + party_id1 + income_num + owner_fac + marital_fac + 
                               log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc + 
                                govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density
                             | id_comb + year | 0 | id_comb, anes_data_v1[  ])

summary(anes_mod_pred_v1_8_TX)

vars_anes_mod_pred_v1_8_TX <- c("Unsecured household debt (log)","UI replacement rate","Financial situation: same","Financial situation: got worse",
                                "Unsecured household debt (log) $\\times$ UI replacement rate",
                                "Unsecured household debt (log) $\\times$ Financial situation: same",
                                "Unsecured household debt (log) $\\times$ Financial situation: got worse",
                                "UI replacement rate $\\times$ Financial situation: same",
                                "UI replacement rate $\\times$ Financial situation: got worse",
                                "Unsecured household debt (log) $\\times$ UI replacement rate $\\times$ Financial situation: same",
                                "Unsecured household debt (log) $\\times$ UI replacement rate $\\times$ Financial situation: got worse")

stargazer(anes_mod_pred_v1_8_TX, 
          covariate.labels = vars_anes_mod_pred_v1_8_TX, dep.var.labels = "Support for welfare spending", 
          label = "anes_mod_pred_v1_triple_int_fin_sit", title = "Effects by Changes in Financial Situation", table.placement = "ht!",
          add.lines = list(c("Mean DV", round(mean(anes_mod_pred_v1_8_TX$fitted.values),2)),
                           c("Individual FE","$\\checkmark$"),
                           c("Year FE","$\\checkmark$"),
                           c("Individual controls","$\\checkmark$"),
                           c("State controls","$\\checkmark$")),
          omit.stat = c("F","ser"), omit="factor", digits=2, align=T, no.space=T, digits.extra=0, type="text", 
          keep = c("pred_ihs_unscrd_debt","replacement_ratio1_yr","fin_sit_last_year"))




##################
### Table A.16 ###
##################

anes_mod_5.4_TX <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr*unemploy_a_lag_grp +
                         unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac + 
                         log_real1gsppc + gsptotal_PC_pct_chg + log_real1exppc + log_real1revpc + afgrant_log + log_disinc + 
                          govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density
                       | abbr + year | 0 | abbr, anes_data_v1)

summary(anes_mod_5.4_TX)


vars_anes_mod_5.4_TX <- c("Unsecured household debt (log)","UI replacement rate","Unemployment rate: high",
                          "Unsecured household debt (log) $\\times$ UI replacement rate",
                          "Unsecured household debt (log) $\\times$ Unemployment rate: high",
                          "UI replacement rate $\\times$ Unemployment rate: high",
                          "Unsecured household debt (log) $\\times$ UI replacement rate $\\times$ Unemployment rate: high")

stargazer(anes_mod_5.4_TX, 
          covariate.labels = vars_anes_mod_5.4_TX, dep.var.labels = "Support for welfare spending", 
          label = "anes_mod_pred_v1_triple_int_unemp", title = "Effects by State-Level Unemployement Rate",table.placement = "ht!",
          add.lines = list(c("Mean DV", round(mean(anes_mod_5.4_TX$fitted.values),2)),
                           c("State FE","$\\checkmark$"),
                           c("Year FE","$\\checkmark$"),
                           c("Individual controls","$\\checkmark$"),
                           c("State controls","$\\checkmark$")),
          omit.stat = c("F","ser"), omit="factor", digits=2, align=T,
          no.space=T, digits.extra=0, type="latex",
          notes.label = "Note: States with low unemployment rates are the omitted baseline.",
          keep = c("pred_ihs_unscrd_debt","replacement_ratio1_yr","unemploy_a_lag_grp"))



##################
### Table A.17 ###
##################

anes_mod_2.6_TX <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr*party_id1 + 
                          unemployed + retired + fin_sit_last_year + income_num + owner_fac + marital_fac + 
                          log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc + 
                          govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density  | id_comb + year | 0 | id_comb, anes_data_v1)

summary(anes_mod_2.6_TX)

vars_anes_mod_2.6_TX <- c("Unsecured household debt (log)","UI replacement rate","Democrat","Republican",
                          "Unsecured household debt (log) $\\times$ UI replacement rate",
                          "Unsecured household debt (log) $\\times$ Democrat",
                          "Unsecured household debt (log) $\\times$ Republican",
                          "UI replacement rate $\\times$ Democrat",
                          "UI replacement rate $\\times$ Republican",
                          "Unsecured household debt (log) $\\times$ UI replacement rate $\\times$ Democrat",
                          "Unsecured household debt (log) $\\times$ UI replacement rate $\\times$ Republican")

stargazer(anes_mod_2.6_TX,covariate.labels = vars_anes_mod_2.6_TX, dep.var.labels = "Support for welfare spending", 
          label = "anes_mod_pred_v1_triple_int_pid", title = "Effects by Party ID", table.placement = "ht!",
          add.lines = list(c("Mean DV", round(mean(anes_mod_2.6_TX$fitted.values),2)),
                           c("Individual FE","$\\checkmark$"),
                           c("Year FE","$\\checkmark$"),
                           c("Individual controls","$\\checkmark$"),
                           c("State controls","$\\checkmark$")),
          omit.stat = c("F","ser"), omit="factor", digits=2, align=T, 
          no.space=T, digits.extra=0, type="latex",
          notes.label = "Note: Independents are the omitted baseline.",
          keep = c("pred_ihs_unscrd_debt","replacement_ratio1_yr","party_id1"))





##################
### Table A.13 ###
##################

# Prep data for support for spending on the poor; remove NA
anes_data_v2 <- anes_data
anes_data_v2[ , fed_spend_welfare_num := NULL ]
anes_data_v2 <- na.omit(anes_data) 

anes_data_v2[ , race2 := factor(race2) ]
anes_data_v2[ , race2 := relevel(race2, "other")]

# Predicted probability has debt 
prob.has.debt <- predict(heckvan1, part = "selection", type="response", anes_data_v2)

# Predicted amount of unsecured debt
pred.amt.unscrd.debt <- predict(heckvan1, part = "outcome",  type="conditional", anes_data_v2)[,2]

# If probability of having debt > 0.5, then give predicted amount, otherwise zero 
anes_data_v2[ , pred_ihs_unscrd_debt := ifelse(prob.has.debt > 0.5, pred.amt.unscrd.debt, 0) ]

# Model
anes_mod_debt_imput_v3.1 <- felm(fed_spend_aid_poor ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac + 
                                   log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc + 
                                   govparty_a + hs_dem_prop_all + median_duration_in_weeks 
                                 | id_comb + year | 0 | id_comb, anes_data_v2)
summary(anes_mod_debt_imput_v3.1)


labels_anes_mod_debt_imput_v3 <- c("Unsecured household debt (log)","UI replacement rate",
                                   "Unemployed","Retired","Democrat","Republican","Financial situation: got worse","Financial situation: got better",
                                   "Household income","Homeowner","Married","GSP (per-capita, log)","Change GSP","Unemployment rate","Expenditures (per-capita, log)",
                                   "Revenues (per-capita, log)","Revenues from Fed. Govt. Transfers","Avg. disposable income (log)",
                                   "Democrat as governor", "Share Democrats in house","Median duration of unemployment",
                                   "Unsecured household debt (log) $\\times$ UI replacement rate")

stargazer(anes_mod_debt_imput_v3.1,
          omit.stat = c("ser","F"), omit= "factor", 
          covariate.labels = labels_anes_mod_debt_imput_v3, dep.var.labels = "Support for spending on aid to the poor",
          add.lines = list(c("Mean DV", round(mean(anes_mod_debt_imput_v3.1$fitted.values),2)),
                           c("Individual FE","$\\checkmark$"),
                           c("Year FE","$\\checkmark$")),
          no.space=T, digits.extra=0, digits=2, align=T, type="latex", 
          title = "Effect of UI Replacement Rates and Unsecured Debt on Support for Spending on the Poor")



################################################################
#### Alternative Heckman model specification (Section A.5.2) ###
################################################################

### Duplicate dataset
anes_data_v3 <- anes_data_v1

### Heckman selection model with unemployed
heckvan1.1 <- selection(has_debt ~ age + income_num + highest_degree + owner + has_children + marital_fac + race2 + gender_num + unemployed,
                        ihs_unscrd_debt_v1 ~ age + income_num + highest_degree + owner + has_children + marital_fac + race2 + gender_num + unemployed,
                        data=scf_data, weights=scf_data$wgt, method="2step")

### Predicted probability has debt 
prob.has.debt_v2 <- predict(heckvan1.1, part = "selection", type="response", anes_data_v3)

#### Predicted amount of unsecured debt
pred.amt.unscrd.debt_v2 <- predict(heckvan1.1, part = "outcome",  type="conditional", anes_data_v3)[,2]

anes_data_v3[ , prob_has_debt := prob.has.debt_v2 ]
anes_data_v3[ , has_debt := ifelse(prob_has_debt > 0.5, 1, 0) ]

# If probability of having debt > 0.5, then give predicted amount, otherwise zero 
anes_data_v3[ , pred_ihs_unscrd_debt := ifelse(prob.has.debt_v2 > 0.5, pred.amt.unscrd.debt_v2, 0) ]

### Predict monthly consumer debt payments
heckvan2.1 <- selection(has_debt ~ age + income_num + highest_degree + owner + has_children + marital_fac + race2 + gender_num + unemployed,
                        ihs_tpay_cons_dbt_v1 ~ age + income_num + highest_degree + owner + has_children + marital_fac + race2 + gender_num + unemployed,
                        data=scf_data, weights=scf_data$wgt, method="2step")

#### Predicted amount of monthly consumer debt repayment
pred.amt.tpay.cons.dbt_v2 <- predict(heckvan2.1, part = "outcome",  type="conditional", anes_data_v3)[,2]

# If probability of having debt > 0.5, then give predicted amount, otherwise zero 
anes_data_v3[ , pred_ihs_tpay_cons_dbt := ifelse(prob.has.debt_v2 > 0.5, pred.amt.tpay.cons.dbt_v2, 0) ]


################# 
### Table A.7 ###
#################

heck.prob_v2 <- heckvan1.1$probit
names(heck.prob_v2$estimate) <- gsub("XS","",names(heck.prob_v2$estimate))

heck.lm_unscrd_dbt_v2 <- heckvan1.1$lm
names(heck.lm_unscrd_dbt_v2$coefficients) <- gsub("XO","",names(heck.lm_unscrd_dbt_v2$coefficients))

heck.lm_tpay_cons_dbt_v2 <- heckvan2.1$lm
names(heck.lm_tpay_cons_dbt_v2$coefficients) <- gsub("XO","",names(heck.lm_tpay_cons_dbt_v2$coefficients))

stargazer(heck.prob_v2, heck.lm_unscrd_dbt_v2, heck.lm_tpay_cons_dbt_v2,
          omit.stat = c("ser"), omit= "factor", 
          no.space=T, digits.extra=0, digits=2, align=T, type="text")

vars_heckit_v2 <- c("Age","Household income","High school","Less than high school","Some college","Homeowner","Has children","Single",
                    "Black","Hispanic","White","Male","Unemployed")

stargazer(heck.prob_v2, heck.lm_unscrd_dbt_v2, heck.lm_tpay_cons_dbt_v2,
          omit.stat = c("ser","F","chi2"), omit= "factor", 
          covariate.labels = vars_heckit_v2,  dep.var.labels = c("Has debt","Unsecured debt (log)"),
          no.space=T, digits.extra=0, digits=2, align=T, type="text")



#################
### Table A.8 ###
#################

### Models for imputed debt level on preferences
anes_mod_debt_imput_v2.1 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr 
                                 | id_comb + year | 0 | id_comb, anes_data_v3)

anes_mod_debt_imput_v2.2 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year
                                 | id_comb + year | 0 | id_comb, anes_data_v3)

anes_mod_debt_imput_v2.3 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac
                                 | id_comb + year | 0 | id_comb, anes_data_v3)

anes_mod_debt_imput_v2.4 <- felm(fed_spend_welfare_num ~ pred_ihs_unscrd_debt*replacement_ratio1_yr + 
                                   unemployed + retired + party_id1 + fin_sit_last_year + income_num + owner_fac + marital_fac + 
                                   log_real1gsppc + gsptotal_PC_pct_chg + unemploy_a + log_real1exppc + log_real1revpc + afgrant_log + log_disinc +
                                   govparty_a + hs_dem_prop_all + median_duration_in_weeks + pollib_median + union_density 
                                 | id_comb + year | 0 | id_comb, anes_data_v3[ ])

stargazer(anes_mod_debt_imput_v2.1, anes_mod_debt_imput_v2.2, anes_mod_debt_imput_v2.3, anes_mod_debt_imput_v2.4,
          omit.stat = c("ser","F"), omit= "factor", 
          covariate.labels = c("Unsecured household debt (log)","UI replacement rate","Unsecured household debt (log) $\\times$ UI replacement rate"),
          dep.var.labels = "Support for welfare spending",
          add.lines = list(c("Mean DV",
                             round(mean(anes_mod_debt_imput_v2.1$fitted.values),2), round(mean(anes_mod_debt_imput_v2.2$fitted.values),2),
                             round(mean(anes_mod_debt_imput_v2.3$fitted.values),2), round(mean(anes_mod_debt_imput_v2.4$fitted.values),2)),
                           c("Individual FE","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$"),
                           c("Year FE","$\\checkmark$","$\\checkmark$","$\\checkmark$","$\\checkmark$"),
                           c("Individual-level covariates","-","$\\checkmark$","$\\checkmark$"),
                           c("Predictor covariates","-","-","$\\checkmark$","$\\checkmark$"),
                           c("State-level covariates","-","-","-","$\\checkmark$")),
          no.space=T, digits.extra=0, digits=2, align=T, type="text",
          keep = c("pred_ihs_unscrd_debt","replacement_ratio1_yr"), 
          title = "Effect of UI Replacement Rates and Unsecured Debt on Support for Welfare Spending; Alternative Imputation Model")

